package com.ruiysoft.service.order.facade;

import com.ruiysoft.controller.integralmdse.vo.InnrIntegralMdseVo;
import com.ruiysoft.controller.mdse.vo.OrderSkuListVo;
import com.ruiysoft.controller.order.vo.OrderPlaceSkuCusVo;
import com.ruiysoft.service.order.bean.OrderPlaceSkuInfoVo;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Date : 2018/11/10
 *
 * @author WenJialu
 */
public enum OrderParseFacade {
    INSTANCE;

    public List<OrderPlaceSkuInfoVo> parseOrderPlaceSkus(List<OrderPlaceSkuCusVo> orderPlaceSkus, Map<Long, OrderSkuListVo> skuInfoMap) {
        return orderPlaceSkus
                .stream()
                .map(ops -> {
                    OrderPlaceSkuInfoVo vo = new OrderPlaceSkuInfoVo();
                    vo.setSkuId(ops.getSkuId());
                    vo.setQuantity(ops.getQuantity());
                    return vo;
                })
                .peek(opsiv -> {
                    OrderSkuListVo skuListVo = skuInfoMap.get(opsiv.getSkuId());
                    opsiv.setSpuId(skuListVo.getSpuId());
                    opsiv.setCategory(skuListVo.getCategory());
                    opsiv.setUnitPrice(skuListVo.getUnitPrice());
                    opsiv.setCostPrice(skuListVo.getCostPrice());
                    opsiv.setListPrice(skuListVo.getListPrice());
                    opsiv.setImgUrl(skuListVo.getPhoto());
                    opsiv.setStatus(skuListVo.getStatus());
                    opsiv.setSkuName(skuListVo.getSkuName());
                    opsiv.setShopId(skuListVo.getShopId());
                    InnrIntegralMdseVo virtualCoinDefine = skuListVo.getIntegralMdse();
                    if(virtualCoinDefine != null){
                        //Todo 类型（1，纯现金或纯积分，2，固定现金+固定积分，3，积分抵现金) ，需要删除魔幻数字
                        opsiv.setPriceStrategy(virtualCoinDefine.getType());
                        opsiv.setVirtualCoinPrice(virtualCoinDefine.getIntegral());
                        if(virtualCoinDefine.getPrice() != null && virtualCoinDefine.getPrice() >= 0L) {
                            //如果为空或为0，则采用通用定义的价格，为了计算运费
                            opsiv.setUnitPrice(virtualCoinDefine.getPrice());
                        }
                    }
                }).collect(Collectors.toList());
    }



}
